package com.lzy.wzy.result;

public class Result<T> {

    private Integer status;
    private String msg;
    private T data;

    public Result(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public Result(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static <T> Result<T> success() {
        return new Result<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
    }

    public static <T> Result<T> success(String msg) {
        return new Result<>(ResponseCode.SUCCESS.getCode(), msg);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(), data);
    }

    public static <T> Result<T> to(int code, String msg) {
        return new Result<>(code, msg);
    }

    public static <T> Result<T> to(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> invalidFormat() {
        return new Result<>(ResponseCode.WRONG_FORMAT.getCode(), ResponseCode.WRONG_FORMAT.getMsg());
    }

    public static <T> Result<T> invalidFormat(String msg) {
        return new Result<>(ResponseCode.WRONG_FORMAT.getCode(), msg);
    }


    public static <T> Result<T> failure() {
        return new Result<>(ResponseCode.FAILURE.getCode(), ResponseCode.FAILURE.getMsg());
    }

    public static <T> Result<T> failure(String msg) {
        return new Result<>(ResponseCode.FAILURE.getCode(), msg);
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
